import { Vector as VectorSource, XYZ } from 'ol/source'
import { Vector as VectorLayer, Tile, Layer } from 'ol/layer'
import { LayerType } from '@/types/index.d.ts'

type LayerType = typeof LayerType

const AddTiandituLayer = (type: LayerType) => {
  return new Tile({
    // 表示除了当前能看到的瓦片外，还会在周围加载低分辨率的瓦片，通过缓存提示用户体验，是一种瓦片预加载技术
    preload: Infinity,
    source: new XYZ({
      url: `http://t0.tianditu.gov.cn/DataServer?T=${type}&x={x}&y={y}&l={z}&tk=590447cdbdf97775b57588a69ebb903d`,
      // 是否横向包裹世界，默认是true
      wrapX: true,
    }),
    properties: {
      name: type
    }
  })
}
export default AddTiandituLayer